package com.goods.controller.business;

import com.goods.business.service.ProductService;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "业务管理-物资资料相关接口")
@RequestMapping("/business/product")
@RestController
public class ProductController {
    @Autowired
    private ProductService productService;

    //分页展示物资数据
    @GetMapping("/findProductList")
    public ResponseBean showProduct(@RequestParam Map pageMap) {
        Map resultMap = productService.showProduct(pageMap);
        return ResponseBean.success(resultMap);
    }

    //添加
    @PostMapping("/add")
    public ResponseBean addProduct(@RequestBody ProductVO productVO) {
        productService.addProduct(productVO);
        return ResponseBean.success();
    }
    
    //回显编辑弹窗
    @GetMapping("/edit/{id}")
    public ResponseBean showEdit(@PathVariable Long id) {
        ProductVO productVO = productService.showEdit(id);
        return ResponseBean.success(productVO);
    }
    
    //修改
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,@RequestBody ProductVO productVO) {
        productService.update(id,productVO);
        return ResponseBean.success();
    }

    //放入回收站
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id) {
        productService.remove(id);
        return ResponseBean.success();
    }

    //从回收站恢复
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id) {
        productService.backOrPublish(id);
        return ResponseBean.success();
    }

    //删除
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id) {
        productService.delete(id);
        return ResponseBean.success();
    }

    //通过审核
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id) {
        productService.backOrPublish(id);
        return ResponseBean.success();
    }
}
